<template>
    <div>
        <el-form   :model="model" :rules="rules" ref="ruleForm" label-width="100px" class="demo-ruleForm">

            <el-form-item label="规格型号" prop="Model">
                <el-input v-model="model.Model"></el-input>
            </el-form-item>

            <el-form-item label="规格编号" prop="Serial">
                <el-input v-model="model.Serial"></el-input>
            </el-form-item>

            <el-form-item label="规格名称" prop="Name">
                <el-input v-model="model.Name"></el-input>
            </el-form-item>
            <el-form-item>
                <el-button type="primary" @click="submitForm">{{ isUpdate?'立即保存':'立即创建' }}</el-button>
                <el-button @click="resetForm">重置</el-button>
            </el-form-item>
        </el-form>
    </div>
</template>

<script>
export default{
    props: {
        model: {
            require: true,
            type: Object
        },
        isUpdate: {
            require: true,
            type: Boolean
        }
    },
    data() {
        return {
            SpecList:[],
            rules: {
                Model: { required: true, message: '请输入规格型号', trigger: 'blur' },
                Serial: { required: true, message: '请输入规格编号', trigger: 'blur' },
                Name: { required: true, message: '请输入规格名称', trigger: 'blur' },
            }
        }
    },
    created(){
        this.getSpecAll();
    },
    methods:{
        submitForm() {
            this.$refs['ruleForm'].validate((valid) => {
                if (valid) {

                    if(this.isUpdate){
                        this.put();
                    }
                    else{
                        this.add();
                    }

                } else {
                    this.showNotify('请输入必填项');
                    return false;
                }
            });
      },
      resetForm() {
        this.$refs['ruleForm'].resetFields();
      },
      add(){
        this.$http.postForm('/api/Spec',{model:this.model},{loading:this.$loading()})
        .then(res=>{
            this.$emit('callback');
        })
      },
      //修改
      put(){
        this.$http.putForm('/api/Spec',{model:this.model},{loading:this.$loading()})
		.then((res)=>{
            this.$emit('callback');
		})
      },
      getSpecAll(){
        this.$http.get('/api/Spec/GetAll')
        .then(res=>{
            this.SpecList=res.Data ;
        })
      }
    }
}
</script>

<style>

</style>